<?php

/**
 * Kontroler domyślny.
 * @method init
 * @category kontroler
 *
 */
class IndexController extends Zend_Controller_Action {

    public function preDispatch() {
        
    }

    /**
     * Pole przechowuje obiekt Zend_Controller_Front
     * @var Zend_Controller_Front
     */
    protected $_request;

    /**
     * Pole przechowuje obiekt wiadomosciManager
     * @var wiadomosciManager
     */
    public $_bUrl;
    private $_flashMessenger;
    private $mnDefault;
    private $_jezyk_lang;
    private $_trans;

    public function init() {
        $this->_helper->layout->setLayoutPath(APPLICATION_PATH . '/layouts');
        $this->_bUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
        $this->_request = Zend_Controller_Front::getInstance()->getRequest();
        $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
        $this->mnDefault = new defaultManager();
        $this->view->bUrl = $this->_bUrl;

        if (!isset($_SESSION['Zend_Translate'])) {
            $locale = new Zend_Locale('auto');
            $jezyk = $locale->getLanguage();

            if (($jezyk != 'pl') && ($jezyk != 'en') && ($jezyk != 'de')) {
                $_SESSION['Zend_Translate'] = 'en_EN';
            } elseif (($jezyk == 'pl') || ($jezyk == 'en') || ($jezyk == 'de')) {
                $_SESSION['Zend_Translate'] = $jezyk.'_'.strtoupper($jezyk);
            }
        }
        $po = new JezykPoManager(array('locale' => $_SESSION['Zend_Translate']));

        $this->_trans = $po->getTranslator();
        $this->view->trans = $this->_trans;

        $lang = explode('_', $_SESSION['Zend_Translate']);
        $this->_jezyk_lang = $lang[0];
        
        $this->view->jezyk_lang = $this->_jezyk_lang;
    }

    /**
     * Domyślna akcja
     */
    public function indexAction() {
        $this->_redirect("Home_page.html");
    }

    public function zajawka1Action() {
        $this->view->headScript()->appendFile($this->_bUrl . '/js/default/zajawka.js', $type = 'text/javascript', $attrs = array());
        $this->view->headScript()->appendFile($this->_bUrl . '/js/swfobject.js');
        $this->view->messages = $this->_flashMessenger->getMessages();

        $this->view->form = $this->mnDefault->formularz();
        $this->view->boxGorny = $this->mnDefault->pobierzBoxStrony(82, $this->_jezyk_lang);
        $this->view->podziekowanie = $this->mnDefault->pobierzBoxStrony(83, $this->_jezyk_lang);
        $this->view->tytul = $strona['nazwa'];
        $this->view->content = $strona['tresc'];


        $this->view->tytul = $tytul;
        $this->view->headTitle($this->view->tytul);
    }

    public function wspolpracaAction() {
        $this->view->headScript()->appendFile($this->_bUrl . '/js/default/zajawka.js', $type = 'text/javascript', $attrs = array());
        $this->view->messages = $this->_flashMessenger->getMessages();

        $this->view->boxGorny = $this->mnDefault->pobierzBoxStrony(84, $this->_jezyk_lang);
        $this->view->boxDolny = $this->mnDefault->pobierzBoxStrony(85, $this->_jezyk_lang);

        $this->view->tytul = $strona['nazwa'];
        $this->view->content = $strona['tresc'];


        $this->view->tytul = $tytul;
        $this->view->headTitle($this->view->tytul);
    }

    public function politykaprywatnosciAction() {
        $this->view->headScript()->appendFile($this->_bUrl . '/js/default/zajawka.js', $type = 'text/javascript', $attrs = array());

        $this->view->messages = $this->_flashMessenger->getMessages();

        $this->view->box = $this->mnDefault->pobierzBoxStrony(86, $this->_jezyk_lang);

        $this->view->tytul = $strona['nazwa'];
        $this->view->content = $strona['tresc'];


        $this->view->tytul = $tytul;
        $this->view->headTitle($this->view->tytul);
    }

    public function obslugaformularzaAction() {
        $this->_helper->layout->disableLayout();
        $this->view->headScript()->appendFile($this->_bUrl . '/js/swfobject.js');
        $dane = $this->_getParam('email', '');

        $this->view->boxGorny = $this->mnDefault->pobierzBoxStrony(82, $this->_jezyk_lang);
        $form = $this->mnDefault->formularz();
        $zwrot = $this->mnDefault->obslugaFormularza($form, array(admMaTeaser::cl_mail => $dane),$this->_jezyk_lang);

        if ($zwrot == 'VALID') {
            $this->view->podziekowanie = $this->mnDefault->pobierzBoxStrony(83, $this->_jezyk_lang);
        } elseif ($zwrot == 'INVALID') {
            $this->view->msg = $form->getMessages();
        }

        $this->view->zwrot = $zwrot;
        $this->view->form = $form;
    }

    public function rezygnacjaAction() {
        $this->view->headScript()->appendFile($this->_bUrl . '/js/default/zajawka.js', $type = 'text/javascript', $attrs = array());
        $mail = $this->_getParam('mail', 'mail@mail.com');
        $kod = $this->_getParam('kod', '1234567890');
        $this->view->msg = $this->mnDefault->rezygnacja($mail, $kod);
    }

    public function tagsAction() {

        header("content-type: text/xml");
        print $this->mnDefault->tagiDoChmury('f4f4f4');
        exit();
    }

    public function podmienjezykAction() {

        $lang = $this->_getParam('lang', 'pl_PL');
        $_SESSION['Zend_Translate'] = $lang;
        $lang_j = explode('_', $lang);
        $this->_jezyk_lang = $lang_j[0];
        $this->_redirect($_SERVER['HTTP_REFERER']);
    }

    public function pokazzdjecieAction() {
//        $kod = $this->_getParam('kod');
//
//        $kat = $this->mnHp->pobierzZdjecie($kod);
//        header('Content-type: ' . $kat['mime']);
//        print pg_unescape_bytea($kat['zdjecie']);
//        exit(0);
    }

}